#!/bin/bash -
#===============================================================================
#
#          FILE: 1.sh
#
#         USAGE: ./1.sh
#
#   DESCRIPTION: 
#
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: YOUR NAME (), 
#  ORGANIZATION: 
#       CREATED: 2018年12月19日 11时57分25秒
#      REVISION:  ---
#===============================================================================

set -o nounset                                  # Treat unset variables as an error
bakfolder=/media/worktemplinux/mysql_databak/
filename=`date +%Y-%m-%d_%H_%M_%S`.sql
bakname=$bakfolder$filename
echo "备份的文件名=$filename"
mysqldump -h192.168.0.198 -P3306 -uroot --default-character-set=utf8 -ph666777kedou --all-databases > $bakname
tar -zcvf $bakname.tar.gz -C $bakfolder $filename
if [ -f $bakname.tar.gz ];then
	echo "压缩完成,删除原文件"
	rm -rf $bakname
else
	echo "压缩失败,保留原文件"
fi
